package com.guosheng.filter;

//import brave.Tracer;
//import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description:  打印该次请求的 traceid 和当前的 span
 * @author: wujt
 * @Date: 2018/8/10
 */
//使用lombok注解打印日志更舒服
//@Slf4j
@Component
public class TraceIdFilter extends AbstractGatewayFilterFactory {

//    @Resource
//    private Tracer tracer;
    private Logger log= LoggerFactory.getLogger(TraceIdFilter.class);
    @Override
    public GatewayFilter apply(Object config) {
        return (exchange, chain) -> {
//            log.info("该次请求的trace》》》》》》》》》" + tracer.toString());
//            log.info("下一步次请求的span》》》》》》》》》" + tracer.nextSpan().toString());
//            log.info("该次请求当前的span》》》》》》》》》" + tracer.currentSpan().toString());
//            log.info("该次请求的traceId》》》》》》》》》" + tracer.currentSpan().context().traceIdString());
            log.info("请求成功");
            return chain.filter(exchange);
        };
    }
}
